//
//  WKAudioTool.m
//  Walk
//
//  Created by cesh on 16/9/9.
//  Copyright © 2016年 cesh. All rights reserved.
//

#import "WKAudioTool.h"
#import "EMCDDeviceManager.h"


@implementation WKAudioTool

+(void)playWithMessage:(EMMessage *)message animation:(UIImageView *)animationImage isMe:(BOOL)isMe{
    
    [animationImage stopAnimating];
    EMVoiceMessageBody *voiceBody = (EMVoiceMessageBody *)message.body;
    // 1.播放
    NSLog(@"localPath %@",voiceBody.localPath);
    NSLog(@"remomePath %@",voiceBody.remotePath);
    [[EMCDDeviceManager sharedInstance] asyncPlayingWithPath:voiceBody.localPath completion:^(NSError *error) {
        NSLog(@"%@", [NSThread currentThread]);
        if (!error) {
            NSLog(@"语音播放完成");
        }else{
            NSLog(@"语音播放失败");
        }
        [animationImage stopAnimating];
    }];
    
    // 2.添加动画
    animationImage.animationDuration = 1;
    animationImage.animationRepeatCount = MAXFLOAT;
    // 设置动画的图片
    if (isMe) {
        animationImage.animationImages = @[
                                             [UIImage imageNamed:@"chat_sender_audio_playing_000"],
                                             [UIImage imageNamed:@"chat_sender_audio_playing_001"],
                                             [UIImage imageNamed:@"chat_sender_audio_playing_002"],
                                             [UIImage imageNamed:@"chat_sender_audio_playing_003"]];
    }else{
        animationImage.animationImages = @[
                                             [UIImage imageNamed:@"chat_receiver_audio_playing000"],
                                             [UIImage imageNamed:@"chat_receiver_audio_playing001"],
                                             [UIImage imageNamed:@"chat_receiver_audio_playing002"],
                                             [UIImage imageNamed:@"chat_receiver_audio_playing003"]];
    }
    
    // 执行动画
    [animationImage startAnimating];
    
}


+(void)stopPlay{
    //停止语音的播放
    [[EMCDDeviceManager sharedInstance] stopPlaying];
    
    //停止动画
//    [_animatingImgView removeFromSuperview];
    
}

@end
